import {Spin, message} from "antd";
import {loginApi} from '@/api'
import {useEffect} from "react";
import MyLocalStorage from "@/utils/Mylocalstorage";
import {USER_KEY} from "@/constants";
import {useNavigate} from "react-router-dom";

const Login = () => {
    const navigate = useNavigate();
    const {code} = Object.fromEntries(new URLSearchParams(window.location.search).entries());

    useEffect(() => {
        ssoLogin();
    }, []);

    const ssoLogin = () => {
        if (code) {
            loginApi({"userName": "admin", "password": "Wpplfq123!"}).then(res => {
                if (res && res.code === 200) {
                    console.log(res)
                    MyLocalStorage.localstorage.setItem(USER_KEY, res.data);
                    navigate('/management');
                }
            })
        }
    }
    return (
        <div>
            <Spin spinning={true} tip={`正在跳转...`}></Spin>
        </div>
    );
};
export default Login;
